package Email.auto.checker;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;


@SuppressWarnings("serial")
public class Notification extends JFrame {

	private String stringMail;
	private int numMails;
	private Dimension screenDim;

	private Container cp;
	private JButton buttonOpenBrowser;
	private JButton buttonClose;
	private JLabel labelNewMessage;
	private JLabel labelLogged;
	private JLabel labelImage;

	private JPanel panelNorth;
	private JPanel panelCenter;
	
	private GridBagConstraints c;

	public Notification(final String mail, final int nMails) {
		stringMail = mail;
		numMails = nMails;

		cp = getContentPane();
		cp.setLayout(new BorderLayout());
		cp.setBackground(new Color(24,24,24));
		
		makeObject();
		arrangeComponents();
		addListener();

		this.setSize(new Dimension(ConstNotification.WIDTH_WINDOW,
				ConstNotification.HEIGHT_WINDOW));

		screenDim = Toolkit.getDefaultToolkit().getScreenSize();
		this.setLocation(
				(int) (screenDim.getWidth() - ConstNotification.WIDTH_WINDOW) - 10,
				(int) (screenDim.getHeight() - ConstNotification.HEIGHT_WINDOW - ConstNotification.BARRA_TAREFAS_TAM));

		this.setResizable(false);
		this.setUndecorated(true);
		this.setVisible(true);
	}

	private void addListener() {
		buttonClose.addActionListener(new ClickButtonClose(this));
		buttonOpenBrowser.addActionListener(new ClickButtonOpenBrowser(this));

	}

	private void arrangeComponents() {
		panelNorth.add(buttonOpenBrowser);
		panelNorth.add(buttonClose);
		panelCenter.add(labelNewMessage, c);
		c.gridy = 2;
		panelCenter.add(labelLogged, c);
		
		
		cp.add(panelNorth, BorderLayout.NORTH);
		cp.add(labelImage, BorderLayout.WEST);
		cp.add(panelCenter, BorderLayout.CENTER);

	}

	
	private void makeObject() {
		panelNorth = new JPanel(new FlowLayout(FlowLayout.RIGHT));
		Color colorNorth = new Color(24, 24, 24);
		panelNorth.setBackground(colorNorth);
	
		c = new GridBagConstraints();
		panelCenter = new JPanel(new GridBagLayout());
		Color colorCenter = new Color(24, 24, 24);
		panelCenter.setBackground(colorCenter);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.gridx = 0;
		c.gridy = 1;
		
		buttonOpenBrowser = new JButton("Open in Browser");
		buttonOpenBrowser.setBackground(new Color(82, 94, 97));
		buttonOpenBrowser.setForeground(Color.WHITE);
		buttonOpenBrowser.setBorderPainted(false);
		buttonOpenBrowser.setFocusPainted(false);
		buttonClose = new JButton("X");
		buttonClose.setBackground(Color.RED);
		buttonClose.setForeground(Color.WHITE);
		buttonClose.setBorderPainted(false);
		buttonClose.setFocusPainted(false);
		Font font = new Font("Calibri", Font.BOLD, 20);
		labelLogged = new JLabel("Logged in as: " + stringMail);
		labelLogged.setFont(new Font("Calibri", Font.ITALIC, 12));
		labelLogged.setForeground(Color.LIGHT_GRAY);
		labelNewMessage = new JLabel("You have " + numMails + " new messages");
		labelNewMessage.setFont(font);
		labelNewMessage.setForeground(new Color(255, 255, 255));
		labelImage = new JLabel("" + numMails);
		labelImage.setFont(new Font("Calibri", Font.BOLD, 50));
		labelImage.setBackground(new Color(24,24,24));
		labelImage.setForeground(new Color(255, 255, 255));
	}

}
